package coder.nav.controller;

import coder.nav.common.JwtToken;
import coder.nav.common.R;
import coder.nav.model.bo.NavSaveMemoBO;
import coder.nav.model.bo.SaveIsExpandBO;
import coder.nav.model.vo.NavMemoTreeVO;
import coder.nav.model.vo.NavMemoVO;
import coder.nav.service.NavMemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "记事本")
@RestController
@RequestMapping("/memo")
public class NavMemoController {

    @Autowired
    private NavMemoService memoService;

    @JwtToken
    @ApiOperation("记事本-保存")
    @PostMapping("/save")
    public R<NavMemoVO> save(@Validated @RequestBody NavSaveMemoBO bo) {
        return new R<>(memoService.saveMemo(bo));
    }

    @JwtToken
    @ApiOperation("记事本-删除")
    @DeleteMapping("/delete")
    public R<Integer> delete(@RequestParam("id") Long id) {
        return new R<>(memoService.deleteMemo(id));
    }

    @JwtToken
    @ApiOperation("记事本-恢复")
    @DeleteMapping("/recover")
    public R<Integer> recover(@RequestParam("id") Long id) {
        return new R<>(memoService.recoverMemo(id));
    }

    @JwtToken
    @ApiOperation("记事本-清空回收站")
    @DeleteMapping("/cleanRecycle")
    public R<Integer> cleanRecycle() {
        return new R<>(memoService.cleanRecycle());
    }

    @JwtToken
    @ApiOperation("记事本-彻底删除")
    @DeleteMapping("/cleanMemo")
    public R<Integer> cleanMemo(@RequestParam("id") Long id) {
        return new R<>(memoService.cleanMemo(id));
    }

    @JwtToken
    @ApiOperation("记事本-详情")
    @GetMapping("/getInfo")
    public R<NavMemoVO> getInfo(@RequestParam("id") Long id) {
        return new R<>(memoService.getInfo(id));
    }

    @JwtToken
    @ApiOperation("记事本-树")
    @GetMapping("/getTree")
    public R<List<NavMemoTreeVO>> getTree() {
        return new R<>(memoService.getTree());
    }

    @JwtToken
    @ApiOperation("记事本-目录")
    @GetMapping("/getFolder")
    public R<List<NavMemoTreeVO>> getFolder() {
        return new R<>(memoService.getFolder());
    }

    @JwtToken
    @ApiOperation("保存节点展开")
    @PostMapping("/saveIsExpand")
    public R<Void> saveIsExpand(@Validated @RequestBody SaveIsExpandBO bo) {
        memoService.saveIsExpand(bo);
        return new R<>();
    }

    @JwtToken
    @ApiOperation("获取节点展开")
    @GetMapping("/getIsExpand")
    public R<List<Long>> getIsExpand() {
        return new R<>(memoService.getIsExpand());
    }

    @ApiOperation("分享页面")
    @GetMapping("/shareInfo")
    public R<NavMemoVO> shareInfo(@RequestParam("userId") Long userId, @RequestParam("shareId") String shareId) {
        return new R<>(memoService.shareInfo(userId, shareId));
    }

}
